package com.itheima.Jiuye14;

import java.util.ArrayList;
import java.util.Random;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class Test111 implements Runnable {
       private Random  a = new Random();
        int[] arr = {10,5,20,50,100,200,500,800,2,80,300,700};
        ArrayList<Integer> list = new ArrayList();
        Lock lock = new ReentrantLock();
    @Override
    public void run() {
        int c = 0;
         while (true){
             lock.lock();
             if (list.size() == arr.length){
                 System.out.println(Thread.currentThread().getName()+"共抽取了"+c+"次");
                 lock.unlock();
                 break;
             }
             int Index = a.nextInt(arr.length);    //创建一个随机数对象，获取随机数
             if (!list.contains(arr[Index])){
                 list.add(arr[Index]);
                 System.out.println("抽奖箱"+Thread.currentThread().getName()+"又产生了一个 "+arr[Index]+" 元大奖");
                 c++;
             }
             lock.unlock();
         }
    }
}
